// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import Vuex from 'vuex'
import Axios from 'axios'
import VueVideoPlayer from 'vue-video-player'
import 'element-ui/lib/theme-chalk/index.css'
import 'video.js/dist/video-js.css' // 引入样式
import 'vue-video-player/src/custom-theme.css' // 引入样式
import 'videojs-flash'
import head from './components/Header.vue'
import footer from './components/Footer.vue'
import cookie from 'vue-cookies'//引入cookie
Vue.use(cookie)
Vue.config.productionTip = false
//注意在main.js中声明，如果不刷新页面，全局只会执行一次
// ESModule
// import * as RongIMLib from '@rongcloud/imlib-v4' 需修改为
//import * as RongIMLib from '@rongcloud/imlib-v4-adapter'
//Vue.prototype.$RongIMLib=RongIMLib;
import LemonIMUI from 'lemon-imui';
import 'lemon-imui/dist/index.css';
Vue.use(LemonIMUI);
//携带cookie请求后台
Axios.defaults.withCredentials=true

Axios.defaults.baseURL="http://localhost:7000/"

//路由守卫 在每次路由抓换时，都需要执行的方法
router.beforeEach((to, from, next) => {
  //if (to.name !== 'login' && !isAuthenticated) next({ name: 'Login' })
  // 如果用户未能验证身份，则 `next` 会被调用两次
  //从cookie中获取到token
  var isAuthenticated=false;
  var token =cookie.get("token");
  //将token串设置到头部中

    console.log("路由守卫"+token);
    Axios.defaults.headers={
      "token":token
    }
    Axios.get("/qflive-user/user/findUserByToken").then(res=>{
        if (res.data.code==1){
          isAuthenticated=true;
        }
      if (to.name !== 'login' && !isAuthenticated) next({ name: 'login' })
      else
        next();
    })

})




Vue.prototype.$axios = Axios
Vue.use(ElementUI)
Vue.use(Vuex)
Vue.component('my-head',head);
Vue.component('my-footer',footer);
Vue.use(VueVideoPlayer, /* {
  options: global default options,
  events: global videojs events
} */)
Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
